/*
 * Created by SharpDevelop.
 * User: MyWife
 * Date: 10/1/2010
 * Time: 5:50 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using popLib;
using System.IO;

namespace TaskNoteManager
{
	/// <summary>
	/// Description of CustomTextBox.
	/// </summary>
	public class CustomTextBox:TextBox
	{
		public delegate void ChangeTabName();
		public event ChangeTabName ChangeTabNameEvent;
		
		public CustomTextBox()
		{
			this.BorderStyle = BorderStyle.None;
		}
		
		public void SetText(string text, Rectangle bound){
			this.Text = text;
			this.Location = new Point( bound.X + 11, bound.Y + 7 );
			this.Size = new Size( bound.Width-11, bound.Height );
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnKeyPress(KeyPressEventArgs e)
		{
			base.OnKeyPress(e);
			if( "/\\?%*:|\"<>".Contains(e.KeyChar.ToString()) )
				e.Handled = true;
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnLeave(EventArgs e)
		{
			base.OnLeave(e);
			this.Hide();
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnKeyUp(KeyEventArgs e)
		{
			base.OnKeyDown(e);
			if( e.KeyCode == Keys.Escape ){
				this.Hide();
			}else if( e.KeyCode == Keys.Enter && StringLib.isValid(this.Text) ){					
				if( ChangeTabNameEvent != null ) ChangeTabNameEvent();
				this.Hide();
			}
		}
	}
}
